{% extends "registration/base.html" %}

{% load i18n %}
{% load qatrack_tags %}

{% block head_title %}{% trans "Log In" %}{% endblock %}

{% block login_active %} class="active"{% endblock %}

{% block require_javascript %}

{% if USE_ADFS %}
  require(['jquery'], function($){
    $("#sign-on-method").on("change", function(){
        $("#sso-wrapper, #qatrack-wrapper").toggleClass("hidden");
    });

  });
{% endif %}

{% endblock require_javascript %}

{% block account_box %}
<div class="box">

  <div class="box-header">
    <h3 class="box-title"><i class="fa fa-sign-in fa-fw" aria-hidden="true"></i> {% trans "Sign in to start your session" %}</h3>
  </div>


  <div class="box-body">
    {% if user.is_authenticated %}
      <div class="alert alert-info margin-bottom-10">
        <strong>{% trans "Note" %}</strong>:
        {% blocktrans %}you are already logged in as {{ user }}.{% endblocktrans %}
      </div>
    {% endif %}

    {% for message in messages %}
      <div class="alert fade in{% if message.tags %} alert-{{ message.tags }}{% endif %}">
        {{ message }}
      </div>
    {% endfor %}

    {% if USE_ADFS %}
      <div class="form">
        <div class="form-group">
          <label class="control-label" for="login-type">{% trans "Login Type" %}</label>
          <select id="sign-on-method" class="form-control input-sm">
            <option value="sso">{% trans "Single Sign On (Login through your hospital network)" %}</option>
            <option value="qatrack" {% if form.errors %}selected={% endif %}>{% trans "QATrack+" %}</option>
          </select>
          <small class="form-text text-muted">{% trans "Choose the login method you would like to use" %}</small>
        </div>
      </div>
      <div id="sso-wrapper" class="{% if form.errors %}hidden{% endif %}">
        <div class="form-group">
          <a href="{% url "django_auth_adfs:login" %}"
            class="btn btn-info btn-flat"
            title="{% trans "Click to login to using your organizations single sign on functionality" %}"
            >
            {% trans "Login with Single Sign On" %}
          </a>
        </div>
      </div>
    {% endif %}
    <div id="qatrack-wrapper" class="{% if USE_ADFS and not form.errors %}hidden{% endif %}">

      <form method="POST" class="form" action="{% url "login" %}" autocapitalize="off">

        {% csrf_token %}
        {% include "_form.html" with form=form %}

        {% if next %}
          <input type="hidden" name="next" value="{{ next }}" />
        {% endif %}

        <div class="form-actions">
          <button type="submit" class="btn btn-info btn-flat">{% trans "Log in" %}</button>
        </div>

      </form>
    </div>

    {% if not user.is_authenticated %}
      <div class="text-muted description-block">{% blocktrans %}If you have any trouble logging in to your account, contact the site administrator.{% endblocktrans %}</div>
    {% endif %}
  </div>
</div>

{% endblock account_box %}
